package com.zhang.reggie.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.naming.Context;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 实现明天理想的唯一障碍是今天的疑虑
 *
 * @Author {张旭军}
 * @Date: 2023/02/04/ 22:53
 * @description
 */
@Configuration
public class ThreadPool {

    @Bean
    public ThreadPoolTaskExecutor taskExecutor(){
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(5);
        taskExecutor.setMaxPoolSize(15);
        taskExecutor.setKeepAliveSeconds(120);
        //解决跨线程之间数据共享问题
        taskExecutor.setTaskDecorator(new ContextTaskDecorator());

        return taskExecutor;
    }
}
